package com.aiolos.springboot.stepbystep.mq;

import com.aiolos.springboot.stepbystep.model.AyMood;
import com.aiolos.springboot.stepbystep.service.IAyMoodService;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 消息的消费者
 */
@Component
public class AyMoodConsumer {

    @Resource
    private IAyMoodService iAyMoodService;

    /**
     * JmsListener：使用JmsListener配置消费者监听的队列ay.queue
     * @param text  text是接收到的消息
     */
    @JmsListener(destination = "ay.queue")
    public void receiveQueue(String text){
        System.out.println("用户发表说说 text = [" + text + "] 成功！");
    }

    /**
     * 在receiveQueue方法中保持说说记录
     * @param ayMood
     */
    @JmsListener(destination = "ay.queue.asyn.save")
    public void receiveQueue(AyMood ayMood){
        iAyMoodService.save(ayMood);
    }
}

